package com.jiawa.wiki.controller;

import com.jiawa.wiki.domain.Test;
import com.jiawa.wiki.service.TestService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: WeiZhen
 * @Date: 2021/6/15 9:59
 * @Description: TODO
 * @Version: 1.0
 **/

@RestController //返回字符串
//@Controller //返回页面
public class TestController {


    @Value("${test.hello:TEST}")
    private String testHello;

    @Resource
    private TestService testService;
/**
 * GET, POST, PUT, DELETE 查看、创建、更新、删除
 * <p>
 * /user?id=1
 * /user/1
 */

// @PostMapping
// @PutMapping
// @DeleteMapping
// @RequestMapping(value = "/user/1", method = RequestMethod.GET) 支持所有请求方式
// @RequestMapping(value = "/user/1", method = RequestMethod.DELETE)
    @GetMapping("/hello")
    public String hello(){
        return "hello" + testHello;
    }

    @PostMapping("/hello/post")
    public String helloPost(String name){
        return "hello! Post" + name;
    }

    @GetMapping("/test/list")
    public List<Test> list(){
        return testService.list();
    }
}
